﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace BabyShop
{
    public partial class _default : System.Web.UI.Page
    {
        public DataTable feature_list;
        public DataTable all_list;
        public int total_products = 0;
        public DataTable cat_list;
        public DataTable brand_list;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string sql = "select top 4 * from products order by quantity desc";
                feature_list = DB_Provider.Read(sql);
                sql = "select top 8 * from products";                                
                all_list = DB_Provider.Read(sql);

                sql = "select count(*) from products";
                //string sql = "select * FROM( SELECT *, ROW_NUMBER() over (ORDER BY ID ) as ct from products ) sub where ct > {0}  and ct <= {1}";
                total_products = DB_Provider.Get(sql);

                sql = "select Categories.id,Categories.name,count(*) as total from categories join products on products.category_id = categories.id group by categories.id,Categories.name";
                cat_list = DB_Provider.Read(sql);

                sql = "select brands.id,brands.name,count(*) as total from brands join products on products.brand_id = brands.id group by brands.id,brands.name";
                brand_list = DB_Provider.Read(sql);
            }
        }
    }
}